package com.easysoft.framework.trademark.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.trademark.mapper.TrademarkMapperExtd;
import com.easysoft.framework.trademark.model.SysTrademark;
import com.easysoft.framework.trademark.model.TrademarkQuery;
import com.easysoft.framework.trademark.model.TrademarkView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("service.TrademarkService")
public class TrademarkService {
    @Autowired
    @Qualifier("mapper.TrademarkMapperExtd")
    private TrademarkMapperExtd trademarkMapperExtd;

    @DataSource(DataSource.SLAVE)
    public List<TrademarkView> selectSysTrademarkByPage(Page page, TrademarkQuery query) {
        int maxRow = trademarkMapperExtd.selectCountTrademark(query);
        if (maxRow == 0){
            return new ArrayList<TrademarkView>();
        }
        page.setMaxRow(maxRow);
        return trademarkMapperExtd.selectSysTrademarkByPage(page,query);
    }

    @DataSource(DataSource.SLAVE)
    public SysTrademark selectByPrimaryKey(String id){
        return trademarkMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int addSysTrademark(SysTrademark trademark){
        trademark.setId(UUIDUtils.getUUID());
        trademark.setCreateTime(new Date());
        return trademarkMapperExtd.insertSelective(trademark);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysTrademark(SysTrademark trademark){
        return trademarkMapperExtd.updateByPrimaryKeySelective(trademark);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysTrademark(String id){
        return trademarkMapperExtd.deleteByPrimaryKey(id);
    }
}
